package com.yorge.controller;

import com.yorge.entities.CommonResult;
import com.yorge.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/order")
public class OrderController {

    public static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVER/payment";

    @Resource
    private RestTemplate restTemplate;

    @RequestMapping("/getPayment/{id}")
    public CommonResult<Payment> getPayment(@PathVariable Long id) {
        return restTemplate.getForObject(PAYMENT_URL + "/getPayment/" + id, CommonResult.class);
    }

    @RequestMapping("/addPayment")
    public CommonResult<String> addPayment(Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL + "/addPayment/", payment, CommonResult.class);
    }
}
